﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Sort : DemoBaseUserControl
    {
        private bool sortAscendingCol = true;
        private bool sortAscendingMultiple = true;
        public Sort()
        {
            InitializeComponent();
            this.Title = "排序";
            this.Description = "Spread .NET  提供排序功能，用户可以通过单击列标题上的“排序指示器”来进行交替的升序和降序排序排序，也可以通过代码实现。下面示例中可以通过点击列头排序指示器进行基于该列的行排序，点击“列排序”按钮执行的排序是基于活动单元格所在行的列排序。“多行排序”按钮执行的排序是基于多行的列排序，首先是第一列，第二列直到最后一列。";
        }

        private void btnSortColumn_Click(object sender, EventArgs e)
        {
            if (sortAscendingCol)
            {
                FpSpread1.Sheets[0].SortColumns(FpSpread1.Sheets[0].ActiveRowIndex, true);
                sortAscendingCol = false;
            }
            else
            {
                FpSpread1.Sheets[0].SortColumns(FpSpread1.Sheets[0].ActiveRowIndex, false);
                sortAscendingCol = true;
            }
        }

        private void btnMultiple_Click(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.SortInfo[] si = new FarPoint.Win.Spread.SortInfo[2];

            if (sortAscendingMultiple)
            {
                si[0] = new FarPoint.Win.Spread.SortInfo(0, true, System.Collections.Comparer.Default);
                si[1] = new FarPoint.Win.Spread.SortInfo(1, true, System.Collections.Comparer.Default);
                FpSpread1.Sheets[0].SortRows(0, FpSpread1.Sheets[0].RowCount, si);
                sortAscendingMultiple = false;
            }
            else
            {
                si[0] = new FarPoint.Win.Spread.SortInfo(0, false, System.Collections.Comparer.Default);
                si[1] = new FarPoint.Win.Spread.SortInfo(1, true, System.Collections.Comparer.Default);
                FpSpread1.Sheets[0].SortRows(0, FpSpread1.Sheets[0].RowCount, si);
                sortAscendingMultiple = true;
            }

        }
        void Sort_Load(object sender, System.EventArgs e)
        {
            //FpSpread1.DataSource = databinding.GetNWINDData("Customers");
            //销售数据清单DataSet dataset = new 销售数据清单DataSet();
            FpSpread1.DataSource = 销售明细表TableAdapter.GetData();
            for (int i = 0; i < FpSpread1_Sheet1.Columns.Count; i++)
            {
                this.FpSpread1_Sheet1.Columns[i].Width = 100; 
            }


            for (int intC = 0; intC < FpSpread1.Sheets[0].ColumnCount; intC++)
                FpSpread1.Sheets[0].Columns[intC].AllowAutoSort = true;
        }
    }
}
